import { describe, it } from "mocha";
import assert from "assert";
import dayjs from "dayjs";
import { MarkApi } from './binance-api'
import { Price } from "../model/binance";
const config = require('../../etc/config')
describe('币安Api测试', () => {
    const { host } = config
    
    const binance = new MarkApi(host, '/api/v3')
    it(`price`, async () => {
        const res: Price[] = await binance.price()
        console.log(JSON.stringify(res));
    })

    it(`priceParam`, async () => {
        const res = await binance.priceParam('ETHBTC')
        console.log(JSON.stringify(res))
    })

    it(`priceParams`, async () => {
        const res = await binance.priceParams(['ETHUSDT', 'BTCUSDT', 'ETHBTCx'])
        console.log(JSON.stringify(res))
    })

    it(`exChangeInfo`, async () => {
        const res = await binance.exChangeInfo()
        console.log(res)
    })

    it(`exChangeInfoParam`, async () => {
        const res = await binance.exChangeInfoParam('ETHBTC')

        console.log(JSON.stringify(res))
    })

    it(`exChangeInfoParams`, async () => {
        const res = await binance.exChangeInfoParams(['ETHBTC', 'BTCUSDT', 'ETHUSDT'])
        console.log(JSON.stringify(res))
    })

    it(`depth`, async () => {
        const res = await binance.depth({ symbol: 'ETHBTC' })
        const resLimit = await binance.depth({ symbol: 'ETHBTC', limit: 1000 })
        console.log(JSON.stringify(res))
        console.log(JSON.stringify(resLimit))
    })

    it(`trades`, async () => {
        const res = await binance.trades({ symbol: 'ETHBTC' })
        const resLimit = await binance.trades({ symbol: 'ETHBTC', limit: 1000 })
        console.log(JSON.stringify(res))
        console.log(JSON.stringify(resLimit))
    })

    it(`aggTrades`, async () => {
        const res = await binance.aggTrades({ symbol: 'ETHBTC' })
        const resLimit = await binance.aggTrades({ symbol: 'ETHBTC', limit: 1000 })
        console.log(JSON.stringify(res))
        console.log(JSON.stringify(resLimit))
    })



    it(`aggTradesByTime`, async () => {
        const endTime = dayjs().valueOf()
        const startTime = dayjs().subtract(1, 'minute').valueOf()
        const res = await binance.aggTradesByTime({ symbol: 'ETHBTC', startTime: startTime, endTime: endTime })
        const resLimit = await binance.aggTradesByTime({ symbol: 'ETHBTC', startTime: startTime, endTime: endTime, limit: 1000 })
        console.log(JSON.stringify(res))
        console.log(JSON.stringify(resLimit))
    })

    it(`avgPriceParam`, async () => {
        const res = await binance.avgPriceParam('ETHBTC')
        console.log(JSON.stringify(res))
    })

    it(`tickerDaily`, async () => {
        const res = await binance.tickerDaily()
        console.log(JSON.stringify(res))
    })

    it(`tickerDailyParam`, async () => {
        const res = await binance.tickerDailyParam(`ETHBTC`)
        console.log(JSON.stringify(res))
    })

    it(`tickerDailyParams`, async () => {
        const res = await binance.tickerDailyParams(['ETHBTC', 'BTCUSDT'])
        console.log(JSON.stringify(res))
    })

    it(`bookTicker`, async () => {
        const res = await binance.bookTicker()
        console.log(res[0].symbol)

        console.log(JSON.stringify(res))
    })

    it(`bookTickerParam`, async () => {
        const res = await binance.bookTickerParam('ETHBTC')

        console.log(JSON.stringify(res))
    })

    it(`bookTickerParams`, async () => {
        const res = await binance.bookTickerParams(['ETHBTC', 'BTCUSDT'])
        console.log(JSON.stringify(res))
    })

    it(`klines`, async () => {
        const res = await binance.klines({ symbol: 'ETHBTC', interval: '1m' })
        const resLimit = await binance.klines({ symbol: 'ETHBTC', interval: '1m', limit: 1000 })
        console.log(JSON.stringify(res))
        console.log(JSON.stringify(resLimit))
    })

    it(`klinesByTime`, async () => {
        const endTime = dayjs().valueOf()
        const startTime = dayjs().subtract(3, 'minute').valueOf()
        const res = await binance.klinesByTime({ symbol: 'ETHBTC', interval: '1m', startTime: startTime, endTime: endTime })
        // const resLimit = await binance.klinesByTime({ symbol: 'ETHBTC', interval: '1m', startTime: startTime, endTime: endTime, limit: 1000 })
        // console.log(JSON.stringify(res[0]))
        // console.log(res.length)
        // console.log(JSON.stringify(resLimit))
    })


    it(`klinesTime`, async () => {
        const endTime = dayjs().valueOf()
        const startTime = dayjs().subtract(3*1000, 'd').valueOf()
        console.log(startTime)
        const res = await binance.kinesTime({ symbol: 'ETHBTC', interval: '3d', startTime: startTime, endTime: endTime, limit: 1000 })
        console.log(JSON.stringify(res))
    })


})